// Set star image when mouse hovers
$('.ratings_stars').hover(
	// Handles the mouseover
	function() {
		$(this).prevAll().andSelf().addClass('ratings_over');
		$(this).nextAll().removeClass('ratings_vote');
	},
	// Handles the mouseout
	function() {
		$(this).prevAll().andSelf().removeClass('ratings_over');
		set_votes();
	}
);

// Click handler
$('.ratings_stars').bind('click', function() {
	var star = this;
	var widget = $(this).parent();
	
	var condition = document.getElementById('item_condition');
	condition.value = $(star).attr('class').charAt(5);
	set_votes() ;
});

 
//Display the star using the condition
function set_votes() {
	var condition = document.getElementById('item_condition').value; 
	
	$('.rate_widget').find('.star_' + condition).prevAll().andSelf().addClass('ratings_vote');
	$('.rate_widget').find('.star_' + condition).nextAll().removeClass('ratings_vote');
}

$(function(){
	set_votes();
});